package com.anke.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.anke.dao.UserDao;
import com.anke.entity.Reservation;
import com.anke.entity.Staff;
import com.anke.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

// 生命服务接口
@Service(interfaceClass = UserService.class)
@Transactional// 添加事务的支持
public class UserServiceImpl implements UserService{

    @Autowired
    private UserDao userDao;

    @Override
    public void register(User user) {
        userDao.register(user);
    }

    @Override
    public boolean login(User user) {
        List<User> u = userDao.selectUserByUsernameAndPassword(user);
        return !u.isEmpty();
    }

    @Override
    public void changePassword(User user) {
        userDao.changePassword(user);
    }

    @Override
    public List<User> findInformation(User user) {
        return userDao.selectUserById(user);
    }

    @Override
    public void updateInformation(User user) {
        userDao.updateUserById(user);
    }

    @Override
    public List<Staff> findAllStaff() {
        List<Staff> staff = userDao.selectAllStaff();
        return staff;
    }

    @Override
    public List<Staff> findBySkill(String skill) {
        return userDao.selectStaffBySkill(skill);
    }

    @Override
    public void reservation(Reservation reservation) {
        userDao.insertReservation(reservation);
    }

//    @Override
//    public void delete(Integer id){
//        Integer count = userDao.findCountByUserId(id);
//        if (count > 0){
//            throw new RuntimeException("当前账号存在关联预约，不能注销");
//        }
//        userDao.delete(id);
//    }
}
